package com.example.work3.controller;

import com.example.work3.entity.Course;
import com.example.work3.pojo.Result;
import com.example.work3.service.CourseSelectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/select")
@CrossOrigin(origins = "http://localhost:8080")
public class SelectController {
    @Autowired
    private CourseSelectService courseSelectService;
    //获取已选课程
    @RequestMapping("/selected/{account}")
    public Result getSelectedCourse(@PathVariable String account){
         return new Result(courseSelectService.selectCourse(account),"200");
    }
    //获取未选选课程
    @RequestMapping("/unselected/{account}")
    public Result getUnselectedCourse(@PathVariable String account){
        return new Result(courseSelectService.noSelectCourse(account),"200");
    }
    //选课
    @RequestMapping("/addCourse/{account}")
    public Result selectCourse(@PathVariable String account ,@RequestBody Course course){
        boolean b = courseSelectService.selectCourse(account, course);
        return new Result(b,"200");
    }
    //退课
    @RequestMapping("/dropCourse/{account}")
    public Result dropCourse(@PathVariable String account,@RequestBody Course course){
        boolean b = courseSelectService.dropCourse(account, course);
        return new Result(b,"200");
    }
}
